/**
 * Copyright 厦门中软海晟信息技术有限公司 版权所有 违者必究 2019
 */
package com.opencvjava.lessons.core;

import com.opencvjava.support.util.CvUtils;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Scalar;
import org.springframework.stereotype.Service;

import static com.opencvjava.support.util.CvUtils.clamp;
import static com.opencvjava.support.util.CvUtils.imshow;
import static com.opencvjava.support.util.CvUtils.mat;
import static org.opencv.imgproc.Imgproc.*;
import static org.opencv.imgcodecs.Imgcodecs.*;
import static org.opencv.core.Core.*;

/**
 * @author : sunzb(sunzb@hsit.com.cn)
 * @date: 2019/1/3
 */
@Service
public class L4_MaskOperation {
    public void test() {
        Mat src = mat("lena.png");
        if (src.empty()) {
            throw new RuntimeException("读取失败");
        }
        imshow("源图", src);
        Mat kernal = new Mat(3, 3, CvType.CV_8S);
        kernal.put(0, 0, 0, -1, 0, -1, 5, -1, 0, -1, 0);
        Mat dst1 = new Mat();
        long time = System.currentTimeMillis();
        filter2D(src, dst1, src.depth(), kernal);
        System.out.println("锐化1：" + (System.currentTimeMillis() - time));
        imshow("锐化1", dst1);
        time = System.currentTimeMillis();
        Mat dst2 = CvUtils.filter2D(src, new int[][]{{0, -1, 0}, {-1, 5, -1}, {0, -1, 0}});
        System.out.println("锐化2：" + (System.currentTimeMillis() - time));
        imshow("锐化2", dst2);
    }
}
